/**
 * @param {number} timeToLive
 */
export var AuthenticationManager = function (timeToLive) {
  this.timeToLive = timeToLive
  this.tokenDict = new Map()
}

/**
 * @param {string} tokenId
 * @param {number} currentTime
 * @return {void}
 */
AuthenticationManager.prototype.generate = function (tokenId, currentTime) {
  this.tokenDict.set(tokenId, currentTime)
}

/**
 * @param {string} tokenId
 * @param {number} currentTime
 * @return {void}
 */
AuthenticationManager.prototype.renew = function (tokenId, currentTime) {
  if (this.tokenDict.has(tokenId) && this.tokenDict.get(tokenId) + this.timeToLive > currentTime) {
    this.tokenDict.set(tokenId, currentTime)
  }
}

/**
 * @param {number} currentTime
 * @return {number}
 */
AuthenticationManager.prototype.countUnexpiredTokens = function (currentTime) {
  let count = 0
  for (const time of this.tokenDict.values()) {
    if (time + this.timeToLive > currentTime) count++
  }
  return count
}

/**
 * Your AuthenticationManager object will be instantiated and called as such:
 * var obj = new AuthenticationManager(timeToLive)
 * obj.generate(tokenId,currentTime)
 * obj.renew(tokenId,currentTime)
 * var param_3 = obj.countUnexpiredTokens(currentTime)
 */
